package leetcode.median;

import java.util.PriorityQueue;

/**
 * ClassName: $215_FindKthLargest
 * Description:
 * date: 2022-01-30 17:32
 *
 * @author liyifan
 */
public class $215_FindKthLargest {
    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> heap = new PriorityQueue<>();
        for (Integer num:nums) {
            heap.add(num);
            if (heap.size() > k) {
                heap.poll();
            }
        }
        return heap.peek();
    }
}
